﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WEB.Model.Entity.Accout;
using WEB.Model.Service;
using WEB.Exceptions;

namespace WEB.Controller
{
    public class LoginAction
    {
        public LoginAction() { }


        /// <summary>
        /// 管理员登陆检查
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="passwd">密码</param>
        /// <returns>检查通过返回管理员实体对象 ，否则返回 NULL</returns>
        public Admin checkLogin(string username,string passwd)
        {
            if (username == "")
            {
                throw new UserNotExistException("用户名不能为空");
            }
            AdminService adminServ = new AdminService();

            Admin admin = adminServ.getAdminByUsername(username);

            if (admin != null)
            {
                if (admin.passwd == passwd)
                {
                    return admin;
                }
                else
                {
                    throw new PasswordNotCorrectException("密码不正确");
                }
            }
            else
            {
                throw new UserNotExistException("用户名不存在");
            }

        }
    }
}